package com.liqi.remote.service;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.liqi.sms.utils.PlatformConfig;
import com.liqi.sms.utils.SmartHttp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.rmi.Remote;
import java.util.HashMap;
import java.util.Map;

/**
 * 设备投放管理Service业务层处理
 *
 * @author xiaoli
 * @date 2022-02-14
 */
@Slf4j
@Service
public class RemoteService
{

    // 1、远程关机
    public String shutdown(String ipAddress,String deviceId,Integer wait){

        String url = ipAddress + HttpParameters.SHUTDOWN;
        log.info("远程关机--请求地址：" + url);
        JSONObject param = JSONUtil.createObj();
        param.set("deviceId",deviceId);
        param.set("wait",wait);
        String reqData = HttpUtil.post(url, param.toString());
        log.info("远程关机--返回值：" + reqData);
        return reqData;

    }

    // 2、远程重启
    public String restart(String ipAddress,String deviceId,Integer wait){

        String url = ipAddress + HttpParameters.RESTART;
        log.info("远程重启--请求地址：" + url);
        JSONObject param = JSONUtil.createObj();
        param.set("deviceId",deviceId);
        param.set("wait",wait);
        String reqData = HttpUtil.post(url, param.toString());
        log.info("远程重启--返回值：" + reqData);
        return reqData;

    }

    // 3、远程拉取日志
    public String getLogFile(String ipAddress){
        String url = "http://"+ipAddress + HttpParameters.GETLOGFILE;
        return url;
    }

    // 4、远程自检
    public String selfcheck(String ipAddress,String deviceId,Integer wait){

        String url = ipAddress + HttpParameters.SELFCHECK;
        log.info("远程关机--请求地址：" + url);
        JSONObject param = JSONUtil.createObj();
        param.set("deviceId",deviceId);
        param.set("wait",wait);
        String reqData = HttpUtil.post(url, param.toString());
        log.info("远程关机--返回值：" + reqData);
        return reqData;

    }



}
